/**
 * Recaf
 *
 * @license MIT-style license
 * @author David Anderson <dave@natulte.net>
 * @copyright Author
 */
var Recaf = {};

Recaf.autocompleter = function() {
  var completer = new Autocompleter.Ajax.Json(
    'bev-search', '/beverage-search', {
      postVar: 'q',
      maxChoices: 20,
      minLength: 3,
      forceSelect: true,
      autoSubmit: true,
      injectChoice: function(token) {
        var choice = new Element(
          'li', {'html': this.markQueryValue(token.desc)});
        choice.inputValue = token.name;
        choice.inputToken = token;
        this.addChoiceEvents(choice).inject(this.choices);
      },
      onSelection: function(element, selected, value, input) {
        $('bev-id').setProperty('value', selected.inputToken.id);
      }
    });
  $('bev-search').focus();
};
